import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.HashSet;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;


public class VocabParser {

	private Pattern linePattern = Pattern.compile("\\d+\\s+([a-zA-Z\\d-_]+).*");
	private Set<String> vocabTags = new HashSet<>();
	
	
	public VocabParser(String path){
		parseVocab(path);
		
		
	}
	
	public Set<String> getTags(){
		return vocabTags;
	}
	private void parseVocab(String path){
		
		File vocabFile = new File(path);
		
		BufferedReader reader = null;
		
		try {
			reader = new BufferedReader( new FileReader(vocabFile));
			String line;
			
			while((line=reader.readLine())!=null){
				line = line.trim();
				if(line.startsWith("#")){
					continue;
				}
				Matcher matcher = linePattern.matcher(line);
				if(matcher.matches()){
					vocabTags.add(matcher.group(1));
				}
				
			}
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			if(reader!=null){
				try {
					reader.close();
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		}
	}
	

}
